
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.1 实例变量方法 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.定义一个模型.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="1.写在前面的话.html">
            
                <a href="1.写在前面的话.html">
            
                    
                    写在前面的话
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="2.搭建环境.html">
            
                <a href="2.搭建环境.html">
            
                    
                    第一章 搭建环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    第二章 模型定义
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="3.sequelize 实例变量.html">
            
                <a href="3.sequelize 实例变量.html">
            
                    
                    2.1 实例变量方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="4.定义一个模型.html">
            
                <a href="4.定义一个模型.html">
            
                    
                    2.2 定义一个模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="5.模型字段类型.html">
            
                <a href="5.模型字段类型.html">
            
                    
                    2.3 模型字段类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="6.导入与配置.html">
            
                <a href="6.导入与配置.html">
            
                    
                    2.3 导入与配置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="3模型关系.html">
            
                <a href="3模型关系.html">
            
                    
                    第三章 模型关系
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="3.1属于.html">
            
                <a href="3.1属于.html">
            
                    
                    3.1 属于
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="3.2包含.html">
            
                <a href="3.2包含.html">
            
                    
                    3.2 包含
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="3.3一对多.html">
            
                <a href="3.3一对多.html">
            
                    
                    3.3 一对多
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="3.4多对多.html">
            
                <a href="3.4多对多.html">
            
                    
                    3.4 多对多
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="3.5多态一对多.html">
            
                <a href="3.5多态一对多.html">
            
                    
                    3.5 多态一对多
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="3.6多态多对多.html">
            
                <a href="3.6多态多对多.html">
            
                    
                    3.6 多态多对多
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="3.7关系嵌套.html">
            
                <a href="3.7关系嵌套.html">
            
                    
                    3.7 关系嵌套
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="4模型查询.html">
            
                <a href="4模型查询.html">
            
                    
                    第四章 模型查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="5查询范围.html">
            
                <a href="5查询范围.html">
            
                    
                    第五章 查询范围 Scope (预定义查询条件)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="6生命周期函数.html">
            
                <a href="6生命周期函数.html">
            
                    
                    第六章 生命周期函数 Hook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="7migrate.html">
            
                <a href="7migrate.html">
            
                    
                    第七章 数据库迁移 Migrate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="8tabel2model.html">
            
                <a href="8tabel2model.html">
            
                    
                    第八章 根据 Table 生成 Model
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >2.1 实例变量方法</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="sequelize-&#x5B9E;&#x4F8B;&#x53D8;&#x91CF;">Sequelize &#x5B9E;&#x4F8B;&#x53D8;&#x91CF;</h1>
<p>&#x5728;&#x5F00;&#x59CB;&#x4E00;&#x4E9B;&#x64CD;&#x4F5C;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x4E86;&#x89E3;&#x4E00;&#x4E0B; sequelize &#x5B9E;&#x4F8B;&#x3002;&#x6211;&#x66FE;&#x7ECF;&#x8BF4;&#x8FC7;&#xFF0C;&#x4E86;&#x89E3;&#x4E00;&#x4E2A;npm &#x5305;&#x6700;&#x5FEB;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x67E5;&#x770B;&#x5B83;&#x7684; d.ts &#x6587;&#x4EF6;&#x3002;&#x6709;&#x673A;&#x4F1A;&#x7684;&#x8BDD;&#xFF0C;&#x6211;&#x63A8;&#x8350;&#x5927;&#x5BB6;&#x8FD8;&#x662F;&#x53EF;&#x4EE5;&#x5B66;&#x4E00;&#x6CE2; TypeScript &#xFF0C;&#x4E0D;&#x8BF4;&#x7ACB;&#x9A6C;&#x7528;&#x8D77;&#x6765;&#xFF0C;&#x53EA;&#x662F;&#x770B;&#x5F97;&#x61C2; d.ts &#x6587;&#x4EF6;&#x4F1A;&#x65B9;&#x4FBF;&#x5F88;&#x591A;&#xFF08;&#x524D;&#x63D0;&#x662F;&#x4F60;&#x6709;&#x6210;&#x719F;&#x7684; JS &#x529F;&#x5E95;&#xFF09;&#x3002;</p>
<blockquote>
<p>&#x6211;&#x8FD9;&#x91CC;&#x4F7F;&#x7528;&#x7684;&#x662F; sublime text&#xFF0C;&#x8DF3;&#x8F6C;&#x662F;&#x6309;&#x7684; F12&#xFF0C;&#x5047;&#x5982;&#x5927;&#x5BB6;&#x4F7F;&#x7528;&#x7684;&#x662F; vscode&#xFF0C;&#x6216;&#x8005;&#x662F; webstorm&#xFF0C;&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x6309;&#x4F4F; Ctrl &#x6216;&#x8005; Command &#x518D;&#x70B9;&#x51FB;&#x5373;&#x53EF;&#x8DF3;&#x8F6C;&#x5230;&#x8BE5;&#x7C7B;&#x578B;&#x7684;&#x5B9A;&#x4E49;&#x3002;</p>
</blockquote>
<p><strong>&#x6253;&#x5F00;<code>node_modules/@types/sequelize/index.d.ts</code> &#x6587;&#x4EF6;</strong>&#xFF0C;&#x5927;&#x6982;&#x5728; <code>5535 - 5831</code> &#x884C;&#x3002;&#x6216;&#x8005;&#x4E5F;&#x53EF;&#x4EE5;&#x67E5;&#x770B;<a href="http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html" target="_blank">&#x5B98;&#x65B9;&#x7684;API</a>&#x3002;</p>
<pre><code>5535:    interface Sequelize extends SequelizeStaticAndInstance, Hooks&lt;any&gt; {
         .......
5831&#xFF1A;
</code></pre><p>&#x6709;&#x7684;&#x4EBA;&#x5C31;&#x8BF4;&#x4E86;&#xFF0C;<code>&#x6211;x&#xFF0C;&#x8FD8;&#x8981;&#x770B; API&#xFF0C;&#x8FD8;&#x8981;&#x770B;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;&#xFF0C;&#x6211;&#x8981;&#x4F60;&#x4F55;&#x7528;&#xFF1F;</code>&#x4F46;&#x662F;&#xFF0C;&#x6211;&#x60F3;&#x5BF9;&#x4F60;&#x8BF4;&#xFF0C;&#x8FD9;&#x4E9B;&#x90FD;&#x662F;&#x5982;&#x4F55;&#x5B66;&#x4E60;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x4F60;&#x4E0D;&#x5B66;&#x4E60;&#x7684;&#x7406;&#x7531;&#xFF0C;&#x95ED;&#x7740;&#x773C;&#x775B;&#x662F;&#x5B66;&#x4E0D;&#x4F1A;&#x7684;&#x3002;</p>
<h4 id="&#x4ED6;&#x6709;&#x4E9B;&#x4EC0;&#x4E48;&#xFF1F;">&#x4ED6;&#x6709;&#x4E9B;&#x4EC0;&#x4E48;&#xFF1F;</h4>
<p>&#x5C5E;&#x6027;&#x3001;&#x65B9;&#x6CD5;&#x5176;&#x5B9E;&#x4E0D;&#x591A;&#xFF0C;&#x4E5F;&#x5C31;&#x5341;&#x51E0;&#x6765;&#x4E2A;&#x3002;</p>
<pre><code>Sequelize: &#x4FDD;&#x5B58;&#x6A21;&#x5757;&#x7684;&#x6784;&#x9020;&#x5668;&#x5F15;&#x7528;
models: &#x53EF;&#x4EE5;&#x62FF;&#x5230;&#x5B9A;&#x4E49;&#x597D;&#x4E86;&#x7684;&#x6A21;&#x578B;
getDialect(): &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x8BF4;&#x660E;&#x662F;&#x901A;&#x8FC7;&#x4F55;&#x79CD;&#x6570;&#x636E;&#x5E93;&#x8FDB;&#x884C;&#x8FDE;&#x63A5;&#x7684;&#xFF0C;&#x6BD4;&#x5982; `mysql`
getQueryInterface(): &#x62FF;&#x5230; QueryInterface &#x7684;&#x5B9E;&#x4F8B;&#x53D8;&#x91CF;
define(): &#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x6A21;&#x578B;&#xFF0C;&#x4ECE;&#x5B9A;&#x4E49;&#x6587;&#x4EF6;&#x91CC;&#x9762;&#x6CE8;&#x91CA;&#x7684;&#x7BC7;&#x5E45;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x77E5;&#x9053;&#x5B83;&#x7684;&#x91CD;&#x8981;&#x6027;
model()&#xFF1A; &#x4F20;&#x9012;&#x4E00;&#x4E2A;&#x6A21;&#x578B;&#x540D;&#x79F0;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x7136;&#x540E;&#x62FF;&#x5230;&#x6A21;&#x578B;
isDefined(): &#x4F20;&#x9012;&#x4E00;&#x4E2A;&#x6A21;&#x578B;&#x540D;&#x79F0;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5224;&#x65AD;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5B9A;&#x4E49;&#x8FC7;&#x4E86;&#x3002;
import()&#xFF1A;&#x5BFC;&#x5165;&#x5B9A;&#x4E49;&#x6A21;&#x578B;&#x6587;&#x4EF6;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;
query()&#xFF1A; &#x6267;&#x884C; sql &#x8BED;&#x53E5;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;
set(): &#x8BBE;&#x7F6E;&#x6570;&#x636E;&#x5E93;&#x53D8;&#x91CF;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;
escape()&#xFF1A; &#x8BBE;&#x7F6E;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;&#x4E32;
createSchema()  schema &#x5176;&#x5B9E;&#x5C31;&#x662F; PostgreSQL &#x7684;&#x8868;
showAllSchemas()
dropSchema()
dropAllSchemas()
sync() &#x901A;&#x8FC7;&#x6A21;&#x578B;&#x5B9A;&#x4E49;&#x521B;&#x5EFA;&#x6570;&#x636E;&#x5E93;&#x8868;&#x683C;
truncate() &#x6E05;&#x7A7A;&#x6240;&#x6709;&#x901A;&#x8FC7;&#x8868;&#x4E2D;&#x7684;&#x6570;&#x636E;
drop() &#x5220;&#x9664;&#x6240;&#x6709;&#x901A;&#x8FC7; sequelize &#x5B9A;&#x4E49;&#x7684;&#x8868;
authenticate() &#x9A8C;&#x8BC1;&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;
validate() &#x8FDB;&#x884C;&#x9A8C;&#x8BC1;&#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;
transaction() &#x5F00;&#x542F;&#x4E8B;&#x52A1;
close() &#x5173;&#x95ED;&#x8FDE;&#x63A5;
databaseVersion() &#x6570;&#x636E;&#x5E93;&#x7248;&#x672C;
</code></pre><p>&#x6211;&#x4E5F;&#x5C1D;&#x8BD5;&#x4E86;&#x591A;&#x6B21; schame &#x7684;&#x4E00;&#x4E9B;&#x65B9;&#x6CD5;&#xFF0C;&#x53D1;&#x73B0;&#x4EC0;&#x4E48;&#x90FD;&#x6CA1;&#x6709;&#x53D1;&#x751F;&#xFF0C;&#x4E8E;&#x662F;&#x6211;&#x4ED4;&#x7EC6;&#x7684;&#x53BB;&#x67E5;&#x770B;&#x4E86;&#x4E00;&#x4E0B;&#x6CE8;&#x91CA;&#x3002;&#x5173;&#x4E8E; schema &#x7684;&#x4E00;&#x4E9B;&#x4E1C;&#x897F; &#x8BF7;&#x6CE8;&#x610F;&#x6CE8;&#x91CA;&#x91CC;&#x6709;&#x8FD9;&#x6837;&#x4E00;&#x53E5;&#x8BDD;&#x3002;schame &#x5176;&#x5B9E;&#x662F; PostgreSQL &#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x8FD9;&#x91CC;&#x4E0D;&#x505A;&#x5173;&#x4E8E;PSQL&#x8FC7;&#x591A;&#x8BB2;&#x89E3;&#x3002;</p>
<pre><code>not a database table. In mysql and sqlite, this command will do nothing.
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="4.定义一个模型.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 2.2 定义一个模型">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.1 实例变量方法","level":"1.4.1","depth":2,"next":{"title":"2.2 定义一个模型","level":"1.4.2","depth":2,"path":"document/4.定义一个模型.md","ref":"./document/4.定义一个模型.md","articles":[]},"previous":{"title":"第二章 模型定义","level":"1.4","depth":1,"ref":"","articles":[{"title":"2.1 实例变量方法","level":"1.4.1","depth":2,"path":"document/3.sequelize 实例变量.md","ref":"./document/3.sequelize 实例变量.md","articles":[]},{"title":"2.2 定义一个模型","level":"1.4.2","depth":2,"path":"document/4.定义一个模型.md","ref":"./document/4.定义一个模型.md","articles":[]},{"title":"2.3 模型字段类型","level":"1.4.3","depth":2,"path":"document/5.模型字段类型.md","ref":"./document/5.模型字段类型.md","articles":[]},{"title":"2.3 导入与配置","level":"1.4.4","depth":2,"path":"document/6.导入与配置.md","ref":"./document/6.导入与配置.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"document/3.sequelize 实例变量.md","mtime":"2017-06-19T05:36:29.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-06-28T08:29:37.466Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

